﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;
using System.Configuration;
using System.Data;

namespace jycboliviaASP.net.Negocio
{
    public class conexionMySql
    {
        // Declaramos las variables:
        public MySqlConnection MySqlConexion = new MySqlConnection();
        public MySqlCommand MySqlComando = new MySqlCommand();
        public MySqlDataReader MySqlLectura;
        public string CadenaDeConexion = ConfigurationManager.ConnectionStrings["MySqlCuadrosXXX"].ConnectionString;

        public conexionMySql()
        {
            MySqlConexion.ConnectionString = CadenaDeConexion;
        }

        public bool Prueba_Conexion()
        {
            try
            {
                MySqlConnection mysql_conexion = new MySqlConnection(CadenaDeConexion);
                mysql_conexion.Open();
                mysql_conexion.Close();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        

        public DataSet consultaMySql(string consulta)
        {
            MySqlComando = new MySqlCommand(consulta);
            MySqlComando.Connection = MySqlConexion;
            MySqlDataAdapter mdatos = new MySqlDataAdapter(MySqlComando);
            MySqlConexion.Open();
            DataSet datosMysql = new DataSet();
            mdatos.Fill(datosMysql);
            MySqlConexion.Close();
            return datosMysql;
        }

        public Boolean ejecutarMySql(string consulta2)
        {
            try
            {                
                MySqlComando = new MySqlCommand(consulta2);
                MySqlComando.Connection = MySqlConexion;
                MySqlConexion.Open();
                MySqlComando.ExecuteNonQuery();
                MySqlConexion.Close();
                return true;
            }
            catch (Exception ex)
            {
                return false;

            }


        }

    }
}